//
//  PersonalViewController.m
//  EMMApp
//
//  Created by Mac on 16/5/11.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "PersonalViewController.h"

/** Api
 *
 *  Api调用导入.h文件
 */
#import "GetHeroListApi.h"

/** Cell
 *
 *  Cell导入.h文件
 */
#import "HeroCell.h"

@interface PersonalViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate> {
    NSString *num;
    NSString *titleOne;
    NSString *numOne;
    NSString *titleTwo;
    NSString *followString;
    NSString *followStringOne;
    BOOL _isOne;
    BOOL _istwo;
    
    NSString *rcString;
    NSString *rgString;
    NSString *qyString;
    
    NSString *rc1String;
    NSString *rg1String;
    NSString *qy1String;
    
    NSString *rcTimer;
    NSString *rgTimer;
    NSString *qyTimer;
    NSMutableArray *rcArr;
    NSMutableArray *rgArr;
    NSMutableArray *qyArr;
}

@property (nonatomic, strong) UITableView *oneTableView;
@property (strong, nonatomic) UIView *headBackView;

@property (strong, nonatomic) UIImageView *headImageview;
@property (strong, nonatomic)UIButton *djBtn;
@property (strong, nonatomic)UIButton *btn;
@property (nonatomic, strong) UIScrollView *mainScrollView;
@property (nonatomic, strong) MenuLitsView *menuOne;
@property (nonatomic, strong) MenuLitsView *menuTwo;

@property (strong, nonatomic) UIView *timerView;
@property (strong, nonatomic) UIButton *timerBtn;

@end

@implementation PersonalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatNavigationController];    
    _oneTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 45, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight-45) style:UITableViewStylePlain];
    
    _oneTableView.delegate = self;
    
    _oneTableView.dataSource = self;
    
    _oneTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:_oneTableView];
    
     [self creatDropDownView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 导航
/**
 *  功能描述：
 *  创建导航栏
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)creatNavigationController {
    [self updateNavBar];
    self.navigationItem.title = @"排行榜";
//    [self configLeftBtn];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setFrame:CGRectMake(0, 0, 54 ,44)];
    [backBtn addTarget:self
                action:@selector(backToPreviousPage:)
      forControlEvents:UIControlEventTouchUpInside];
    [backBtn setBackgroundColor:[UIColor clearColor]];
    [backBtn setImage:[UIImage imageNamed:@"ico_back"] forState:UIControlStateNormal];
    backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    if (EMM_WIDTH <= 320) {
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }else if (EMM_WIDTH > 375){
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    }else{
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];

}

- (void)backToPreviousPage:(UIButton *)btn {
    [self removeSubViewOne];
    [self removeSubViewTWo];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
    rcArr = [[NSMutableArray alloc] init];
    rgArr = [[NSMutableArray alloc] init];
    qyArr = [[NSMutableArray alloc] init];
    num = @"0";
    numOne = @"0";
    followString = @"1";
    followStringOne = @"1";
    [self showHudInWindow:@"请稍等正在加载..."];
    [self PostGetHeroListApiTimeType:@"1" cusType:@"1" cusSort:followStringOne];
    [self PostGetHeroListApiTimeType:@"1" cusType:@"2" cusSort:followStringOne];
    [self PostGetHeroListApiTimeType:@"1" cusType:@"3" cusSort:followStringOne];
}

/**
 *  功能描述：
 *  获取英雄榜数据Api接口
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)PostGetHeroListApiTimeType:(NSString *)timeType
                           cusType:(NSString *)cusType
                           cusSort:(NSString *)cusSort {
    [qyArr  removeAllObjects];
    [rgArr removeAllObjects];
    [rcArr removeAllObjects];
    GetHeroListApi *api = [[GetHeroListApi alloc] initWithTimeType:timeType cusType:cusType cusSort:cusSort];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetHeroListApi *result = (GetHeroListApi *)request;
        if (result.isSuccess) {
            GetHeroList *get = result.resultData;
            if ([cusType isEqualToString:@"1"]) {
                for (HeroList *list in get.heroList) {
                    [rcArr addObject:list];
                }
            }else if ([cusType isEqualToString:@"2"]) {
                for (HeroList *list in get.heroList) {
                    [rgArr  addObject:list];
                }
            }else if ([cusType isEqualToString:@"3"]) {
                for (HeroList *list in get.heroList) {
                    [qyArr addObject:list];
                }
            }
        } else {
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
        [_oneTableView reloadData];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark - 跳出层初始化
/**
 *  功能描述：
 *  创建初始化视图Api接口
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)creatDropDownView {
    self.headBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 45)];
    self.headBackView.backgroundColor = [UIColor colorFromHexCode:@"##fff5e9"];
    [self.view addSubview:self.headBackView];
    
    UILabel *l1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 44.5, EMM_WIDTH, 0.5)];
    l1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    [self.headBackView addSubview:l1];
    
    _djBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _djBtn.frame = CGRectMake(0, 5, EMM_WIDTH/2, 32);
    _djBtn.titleLabel.font = [UIFont systemFontOfSize:16];
//    _djBtn.tintColor = [UIColor colorFromHexCode:@"#e97300"];
//    _djBtn.tintColor = [UIColor grayColor];
    [_djBtn setTitle:@"筛选" forState:UIControlStateNormal];
    [_djBtn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
    [_djBtn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];
    //设置button背景显示图片
  
    _djBtn.tag = 2001;
//    [_djBtn setImageEdgeInsets:UIEdgeInsetsMake(0, _djBtn.titleLabel.bounds.size.width+EMM_WIDTH/2-60, 0, _djBtn.titleLabel.bounds.size.width)];
    [_djBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];

    [_djBtn addTarget:self action:@selector(headButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.headBackView addSubview:_djBtn];
    
    _btn = [UIButton buttonWithType:UIButtonTypeCustom];
    _btn.frame = CGRectMake(EMM_WIDTH/2, 5, EMM_WIDTH/2, 32);
    _btn.titleLabel.font = [UIFont systemFontOfSize:16];

    [_btn setTitle:@"排序" forState:UIControlStateNormal];
    [_btn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
    _btn.tag = 2002;
    [_btn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];    //设置button背景显示图片
//    [_btn setImageEdgeInsets:UIEdgeInsetsMake(0, _btn.titleLabel.bounds.size.width+EMM_WIDTH/2-60, 0, _btn.titleLabel.bounds.size.width)];
    [_btn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
    [_btn addTarget:self action:@selector(headButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.headBackView addSubview:_btn];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(EMM_WIDTH/2, 7.5, 1, 30)];
    label.backgroundColor = [UIColor colorFromHexCode:@"##ffa626"];
    [self.headBackView addSubview:label];

    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
    CGSize textSize = [@"筛选" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    _headImageview = [[UIImageView alloc] initWithFrame:CGRectMake((EMM_WIDTH/2-textSize.width)/2-10, 43, textSize.width, 2)];
    _headImageview.backgroundColor = [UIColor colorFromHexCode:@"#5A5A5A"];
    [self.headBackView addSubview:self.headImageview];
    _isOne = YES;
    _istwo = YES;
}

/**
 *  功能描述：
 *  设置ScrollView一些属性
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)setScrollView:(UIScrollView *)scrollView width:(CGFloat)width {
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
    scrollView.contentSize = CGSizeMake(width,scrollView.bounds.size.height);
}

#pragma mark - 顶部按键响应事件
/**
 *  功能描述：
 *  顶部排序方式按钮事件
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)headButtonClick:(UIButton *)button {
    [self headLineViewScrollWithIndex:button.tag-2001];
    [UIView animateWithDuration:0.5 animations:^{
        _mainScrollView.contentOffset = CGPointMake((button.tag-2001)*ScreenSize.width, 0);
    }];
    if (button.tag == 2001) {
        if (_isOne == YES ) {
            [self menulistShowUIOne];
            [_djBtn setImage:[UIImage imageNamed:@"sj_up"] forState:UIControlStateNormal];
            _isOne = NO;
            [_btn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];    //设置button背景显示图片
            [_djBtn setTitleColor:[UIColor colorFromHexCode:@"#e97300"] forState:UIControlStateNormal];
            [_btn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
            //设置button背景显示图片
            _headImageview.backgroundColor = [UIColor colorFromHexCode:@"#e97300"];
            
        }else {
            [self removeSubViewOne];
            [_djBtn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];
            _isOne = YES;
            [_djBtn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
            _headImageview.backgroundColor = [UIColor colorFromHexCode:@"#5A5A5A"];
        }
        _istwo = YES;
        [self removeSubViewTWo];
        
    }else if (button.tag == 2002) {
        
        if (_istwo == YES ) {
            [self menulistShowUITwo];
            [_btn setImage:[UIImage imageNamed:@"sj_up"] forState:UIControlStateNormal];
            _istwo = NO;
            [_djBtn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];    //设置button背景显示图片
            
            [_btn setTitleColor:[UIColor colorFromHexCode:@"#e97300"] forState:UIControlStateNormal];
            [_djBtn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
            _headImageview.backgroundColor = [UIColor colorFromHexCode:@"#e97300"];
            
        }else {
            [self removeSubViewTWo];
            [_btn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];
            _istwo = YES;
            [_btn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
            _headImageview.backgroundColor = [UIColor colorFromHexCode:@"#5A5A5A"];
        }
        _isOne = YES;
        [self removeSubViewOne];
    }
    [_btn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
    [_djBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
}

#pragma mark - 创建筛选弹出框
/**
 *  功能描述：
 *  按时间排序弹出筛选菜单
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)menulistShowUIOne {
    //1、意向等级（默认）；2、意向户型；3、需求面积；4、预算总价；5、客户年龄；6、客户状态
    NSArray *arr = [NSArray arrayWithObjects:
                    @"今日",@"昨天",@"本周",
                    @"上周",@"本月",@"上月",@"三月内",@"全部", nil];
    _menuOne = [[MenuLitsView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight+45, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight-45) items:arr indet:num isShowUI:NO guodu:6*50];
    _menuOne.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:_menuOne];
    __weak MenuLitsView *weakSelf = _menuOne;
    [weakSelf setMenuLitsBlock:^(NSString *title, NSString *indet) {
        [_djBtn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];
        if ([NSString isStringEmpty2:indet] == NO) {
            num = indet;
            titleOne = title;
            followString = [NSString stringWithFormat:@"%ld",[indet integerValue]+1];
            if ([indet isEqualToString:@"0"]) {
                [_djBtn setTitle:@"今日" forState:UIControlStateNormal];
            }else {
                [_djBtn setTitle:title forState:UIControlStateNormal];
            }
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
            CGSize textSize = [_djBtn.titleLabel.text boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
            self.headImageview.frame = CGRectMake((EMM_WIDTH/2-textSize.width)/2-10, 43, textSize.width, 2);
            [self showHudInWindow:@"请稍等正在加载..."];
            [self PostGetHeroListApiTimeType:followString cusType:@"1" cusSort:followStringOne];
            [self PostGetHeroListApiTimeType:followString cusType:@"2" cusSort:followStringOne];
            [self PostGetHeroListApiTimeType:followString cusType:@"3" cusSort:followStringOne];
            [_oneTableView reloadData];
        }else {
            if ([NSString isStringEmpty2:titleOne] == NO) {
                [_djBtn setTitle:titleOne forState:UIControlStateNormal];
            }else {
                [_djBtn setTitle:@"今日" forState:UIControlStateNormal];
            }
        }
        [_djBtn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
        _headImageview.backgroundColor = [UIColor colorFromHexCode:@"#5A5A5A"];
        _isOne = YES;
        [_btn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
        [_djBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
        [weakSelf removeFromSuperview];
    }];
}

#pragma mark - 创建排序弹出框
/**
 *  功能描述：
 *  筛选菜单按钮筛选方式（按数量，按金额）
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)menulistShowUITwo {
    
    NSArray *arr = [NSArray arrayWithObjects:@"按数量",@"按金额",nil];
    _menuTwo = [[MenuLitsView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight+45, EMM_WIDTH, EMM_HEIGHT-SafeAreaTopHeight-45) items:arr indet:numOne isShowUI:NO guodu:arr.count*50];
    _menuTwo.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [[UIApplication sharedApplication].keyWindow addSubview:_menuTwo];
    __weak MenuLitsView *weakSelf = _menuTwo;
    [weakSelf setMenuLitsBlock:^(NSString *title, NSString *indet) {
        [_btn setImage:[UIImage imageNamed:@"sj_down"] forState:UIControlStateNormal];
        if ([NSString isStringEmpty2:indet] == NO) {
            numOne = indet;
            titleTwo = title;
            followStringOne = [NSString stringWithFormat:@"%ld",[indet integerValue]+1];
            [_btn setTitle:title forState:UIControlStateNormal];
            [self showHudInWindow:@"请稍等正在加载..."];
            [self PostGetHeroListApiTimeType:followString cusType:@"1" cusSort:followStringOne];
            [self PostGetHeroListApiTimeType:followString cusType:@"2" cusSort:followStringOne];
            [self PostGetHeroListApiTimeType:followString cusType:@"3" cusSort:followStringOne];
            [_oneTableView reloadData];
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
            CGSize textSize = [_btn.titleLabel.text boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
            self.headImageview.frame = CGRectMake((EMM_WIDTH/2-textSize.width)/2+EMM_WIDTH/2-10, 43, textSize.width, 2);
        }else {
            if ([NSString isStringEmpty2:titleOne] == NO) {
                [_btn setTitle:titleTwo forState:UIControlStateNormal];
            }else {
                [_btn setTitle:@"按数量" forState:UIControlStateNormal];
            }
        }
        [_btn setTitleColor:[UIColor colorFromHexCode:@"#5A5A5A"] forState:UIControlStateNormal];
        _headImageview.backgroundColor = [UIColor colorFromHexCode:@"#5A5A5A"];
        _istwo = YES;
        [_btn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
        [_djBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:5];
        [weakSelf removeFromSuperview];
    }];
}

#pragma mark - 删除筛选弹出框
- (void)removeSubViewOne {
    [_menuOne removeFromSuperview];
    _menuOne = nil;
}

#pragma mark - 删除排序弹出框
- (void)removeSubViewTWo {
    [_menuTwo removeFromSuperview];
    _menuTwo = nil;
}

#pragma mark - 顶部线移动,
/**
 *  功能描述：
 *  顶部点击筛选按钮下划线移动动画和箭头方向改变
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (void)headLineViewScrollWithIndex:(NSInteger)index {
    
    [UIView animateWithDuration:0.15 animations:^{
        if (index == 0) {
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
            CGSize textSize = [_djBtn.titleLabel.text boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
            self.headImageview.frame = CGRectMake((EMM_WIDTH/2-textSize.width)/2-10, 43, textSize.width, 2);
        }else if (index == 1) {
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
            CGSize textSize = [_btn.titleLabel.text boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
            self.headImageview.frame = CGRectMake((EMM_WIDTH/2-textSize.width)/2+EMM_WIDTH/2-10, 43, textSize.width, 2);
        }
    }];
}

#pragma mark - tableView代理
/**
 *  功能描述：
 *  UITableView代理方法事件
 *  更新时间：2016/12/22
 *  更新人：guowei
 */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 200;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId = @"HeroCell";
    HeroCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"HeroCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.herImageV1.frame = CGRectMake(20, 10, 60, 60);
    cell.herImageV2.frame = CGRectMake(20, 10, 60, 60);
    cell.herImageV3.frame = CGRectMake(20, 10, 60, 60);
    
    [cell.herImageV1.layer setCornerRadius:(cell.herImageV1.frame.size.height/2)];
    [cell.herImageV1.layer setMasksToBounds:YES];
    [cell.herImageV1 setContentMode:UIViewContentModeScaleAspectFill];
    [cell.herImageV1 setClipsToBounds:YES];
    cell.herImageV1.layer.shadowColor = [UIColor blackColor].CGColor;
    cell.herImageV1.layer.shadowOffset = CGSizeMake(4, 4);
    cell.herImageV1.layer.shadowOpacity = 0.5;
    cell.herImageV1.layer.shadowRadius = 1.0;
    cell.herImageV1.layer.borderColor = [[UIColor colorFromHexCode:@"#f5f5f5"] CGColor];
    cell.herImageV1.layer.borderWidth = 1.0f;
    cell.herImageV1.userInteractionEnabled = YES;
    
    [cell.herImageV2.layer setCornerRadius:(cell.herImageV2.frame.size.height/2)];
    [cell.herImageV2.layer setMasksToBounds:YES];
    [cell.herImageV2 setContentMode:UIViewContentModeScaleAspectFill];
    [cell.herImageV2 setClipsToBounds:YES];
    cell.herImageV2.layer.shadowColor = [UIColor blackColor].CGColor;
    cell.herImageV2.layer.shadowOffset = CGSizeMake(4, 4);
    cell.herImageV2.layer.shadowOpacity = 0.5;
    cell.herImageV2.layer.shadowRadius = 1.0;
    cell.herImageV2.layer.borderColor = [[UIColor colorFromHexCode:@"#f5f5f5"] CGColor];
    cell.herImageV2.layer.borderWidth = 1.0f;
    cell.herImageV2.userInteractionEnabled = YES;
    
    [cell.herImageV3.layer setCornerRadius:(cell.herImageV3.frame.size.height/2)];
    [cell.herImageV3.layer setMasksToBounds:YES];
    [cell.herImageV3 setContentMode:UIViewContentModeScaleAspectFill];
    [cell.herImageV3 setClipsToBounds:YES];
    cell.herImageV3.layer.shadowColor = [UIColor blackColor].CGColor;
    cell.herImageV3.layer.shadowOffset = CGSizeMake(4, 4);
    cell.herImageV3.layer.shadowOpacity = 0.5;
    cell.herImageV3.layer.shadowRadius = 1.0;
    cell.herImageV3.layer.borderColor = [[UIColor colorFromHexCode:@"#f5f5f5"] CGColor];
    cell.herImageV3.layer.borderWidth = 1.0f;
    cell.herImageV3.userInteractionEnabled = YES;
    
    if (indexPath.row == 0) {
        cell.titleImageV.image = [UIImage imageNamed:@"icon_phb_rc"];
        cell.titleLabel.text = @"认筹";
        if (rcArr.count == 3) {
            HeroList *list = [rcArr objectAtIndex:0];
            HeroList *list1 = [rcArr objectAtIndex:1];
            HeroList *list2 = [rcArr objectAtIndex:2];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            }];
            
            [cell.herImageV2 sd_setImageWithURL:[NSURL URLWithString:list1.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                
            }];
            [cell.herImageV3 sd_setImageWithURL:[NSURL URLWithString:list2.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                
            }];
           
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@)",list1.agent,list1.cusNum];
                cell.herNum3.text = [NSString stringWithFormat:@"%@(%@)",list2.agent,list2.cusNum];

            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@万元)",list1.agent,list1.cusAmount];
                cell.herNum3.text = [NSString stringWithFormat:@"%@(%@万元)",list2.agent,list2.cusAmount];

            }
        }if (rcArr.count == 2) {
            HeroList *list = [rcArr objectAtIndex:0];
            HeroList *list1 = [rcArr objectAtIndex:1];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            [cell.herImageV2 sd_setImageWithURL:[NSURL URLWithString:list1.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@)",list1.agent,list1.cusNum];

            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@万元)",list1.agent,list1.cusAmount];

            }
            cell.heroV3.hidden = YES;
        }if (rcArr.count == 1) {
            HeroList *list = [rcArr objectAtIndex:0];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
            }
            cell.heroV3.hidden = YES;
            cell.heroV2.hidden = YES;

        }else if (rcArr.count == 0){
            cell.heroV3.hidden = YES;
            cell.heroV2.hidden = YES;
            cell.heroV1.hidden = YES;
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 40, EMM_WIDTH, cell.frame.size.height-40)];
            view.backgroundColor = [UIColor whiteColor];
            [cell addSubview:view];
            UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, (view.frame.size.height-20)/2, EMM_WIDTH, 20)];
            l.text = @"当前没有记录";
            l.textAlignment = NSTextAlignmentCenter;
            l.font = [UIFont systemFontOfSize:14];
            [view addSubview:l];
        }
    }else if (indexPath.row == 1) {
        cell.titleImageV.image = [UIImage imageNamed:@"icon_phb_rg"];
        cell.titleLabel.text = @"认购";
        if (rgArr.count == 3) {
            HeroList *list = [rgArr objectAtIndex:0];
            HeroList *list1 = [rgArr objectAtIndex:1];
            HeroList *list2 = [rgArr objectAtIndex:2];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            [cell.herImageV2 sd_setImageWithURL:[NSURL URLWithString:list1.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            [cell.herImageV3 sd_setImageWithURL:[NSURL URLWithString:list2.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@)",list1.agent,list1.cusNum];
                cell.herNum3.text = [NSString stringWithFormat:@"%@(%@)",list2.agent,list2.cusNum];

            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@万元)",list1.agent,list1.cusAmount];
                cell.herNum3.text = [NSString stringWithFormat:@"%@(%@万元)",list2.agent,list2.cusAmount];

            }
        }if (rgArr.count == 2) {
            HeroList *list = [rgArr objectAtIndex:0];
            HeroList *list1 = [rgArr objectAtIndex:1];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            [cell.herImageV2 sd_setImageWithURL:[NSURL URLWithString:list1.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@)",list1.agent,list1.cusNum];

            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@万元)",list1.agent,list1.cusAmount];
            }
            cell.heroV3.hidden = YES;
        }if (rgArr.count == 1) {
            HeroList *list = [rgArr objectAtIndex:0];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];

            }
            cell.heroV3.hidden = YES;
            cell.heroV2.hidden = YES;

        }else if (rgArr.count == 0) {
            cell.heroV3.hidden = YES;
            cell.heroV2.hidden = YES;
            cell.heroV1.hidden = YES;

            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 40, EMM_WIDTH, cell.frame.size.height-40)];
            view.backgroundColor = [UIColor whiteColor];
            [cell addSubview:view];
            UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, (view.frame.size.height-20)/2, EMM_WIDTH, 20)];
            l.text = @"当前没有记录";
            l.textAlignment = NSTextAlignmentCenter;
            l.font = [UIFont systemFontOfSize:14];
            [view addSubview:l];
        }
        
    }else if (indexPath.row == 2) {
        cell.titleImageV.image = [UIImage imageNamed:@"icon_phb_qy"];
        cell.titleLabel.text = @"签约";
        if (qyArr.count == 3) {
            HeroList *list = [qyArr objectAtIndex:0];
            HeroList *list1 = [qyArr objectAtIndex:1];
            HeroList *list2 = [qyArr objectAtIndex:2];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            [cell.herImageV2 sd_setImageWithURL:[NSURL URLWithString:list1.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            [cell.herImageV3 sd_setImageWithURL:[NSURL URLWithString:list2.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@)",list1.agent,list1.cusNum];
                cell.herNum3.text = [NSString stringWithFormat:@"%@(%@)",list2.agent,list2.cusNum];

            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@万元)",list1.agent,list1.cusAmount];
                cell.herNum3.text = [NSString stringWithFormat:@"%@(%@万元)",list2.agent,list2.cusAmount];

            }
        }if (qyArr.count == 2) {
            HeroList *list = [qyArr objectAtIndex:0];
            HeroList *list1 = [qyArr objectAtIndex:1];
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            [cell.herImageV2 sd_setImageWithURL:[NSURL URLWithString:list1.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
                
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@)",list1.agent,list1.cusNum];
            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
                
                cell.herNum2.text = [NSString stringWithFormat:@"%@(%@万元)",list1.agent,list1.cusAmount];
            }
            cell.heroV3.hidden = YES;

        }if (qyArr.count == 1) {
            HeroList *list = [qyArr objectAtIndex:0];
            
            [cell.herImageV1 sd_setImageWithURL:[NSURL URLWithString:list.headPic] placeholderImage:[UIImage imageNamed:@"touxiang"]];
            if ([followStringOne isEqualToString:@"1"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@)",list.agent,list.cusNum];
            }else if ([followStringOne isEqualToString:@"2"]) {
                cell.herNum1.text = [NSString stringWithFormat:@"%@(%@万元)",list.agent,list.cusAmount];
            }
            cell.heroV3.hidden = YES;
            cell.heroV2.hidden = YES;

        }else if (qyArr.count == 0) {
            cell.heroV3.hidden = YES;
            cell.heroV2.hidden = YES;
            cell.heroV1.hidden = YES;

            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 40, EMM_WIDTH, cell.frame.size.height-40)];
            view.backgroundColor = [UIColor whiteColor];
            [cell addSubview:view];
            UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(0, (view.frame.size.height-20)/2, EMM_WIDTH, 20)];
            l.text = @"当前没有记录";
            l.textAlignment = NSTextAlignmentCenter;
            l.font = [UIFont systemFontOfSize:14];
            [view addSubview:l];
        }
    }
    return cell;
}



@end
